#!/bin/bash

#config

MY_PHP_BIN=/usr/local/php/bin/php

MY_PROJECT_ROOT="$(cd `dirname $0`;cd ../../; pwd)/"

#common fun
isFileLocked(){
    param=$*

    files=`ps aux | grep "think ${param}" | grep "${MY_PHP_BIN}"`;

    if [ "${files}" ]; then
    echo 1;
    exit;
    else
    echo 0;
    exit;
    fi
}


main(){
    param=$*
    islocked=`isFileLocked ${param}`;
    if [ "$islocked" -eq 1  ]; then
    echo "think ${param} is runing........,please wait!";
    exit 1;
    fi
    echo "think ${param} is exit!";
    echo "${MY_PHP_BIN} ${MY_PROJECT_ROOT}think ${param}";
    CLI_STR="${MY_PHP_BIN} ${MY_PROJECT_ROOT}think ${param}"

    ${CLI_STR}
}

main1(){
    param=$*
    islocked=`isFileLocked ${param}`;
    if [ "$islocked" -eq 1  ]; then
    echo "think ${param} is runing........,please wait!";
    exit 1;
    fi

    CLI_STR="${MY_PHP_BIN} ${MY_PROJECT_ROOT}think ${param} "

    ${CLI_STR} &
}